﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeChatCardProxy.WebApiEntity;
using ZilLion.Service.Core.DapperWrapper;

namespace ZilLion.Service.WeChatCardProxy.Domain
{
    public class Authorization_infoRepository : Respository<Authorization_info>, IAuthorization_infoRepository
    {
        public Authorization_infoRepository()
        {
            Context = new WeChatCardProxyContext();
        }

        public void InsertAuthorization_info(Authorization_info Auth)
        {
            this.Add(Auth);
        }

        public void UpdateAuthorization_info(Authorization_info Auth)
        {
            this.Modify(Auth);
        }

        public Authorization_info GetAuthorization_info(Authorization_info Auth)
        {
            var item = this.GetList("select * from Authorization_info where authorizer_appid=@authorizer_appid", new { Auth.authorizer_appid }).FirstOrDefault();
            return item;
        }

        public bool GetValideAuthorization_info(string Authorization_appid)
        {
            bool item =
                this.GetList<long>(
                    "select count(*) from Authorization_appid_Config where IsDelete=0 and Authorization_appid=@Authorization_appid",
                    new {Authorization_appid}).FirstOrDefault() >0;
            return item;
        }

        public Authorization_Config GetAuthorization_info(string Authorization_appid)
        {
            Authorization_Config item =
                this.GetList<Authorization_Config>(
                    "select * from Authorization_appid_Config where IsDelete=0 and Authorization_appid=@Authorization_appid",new { Authorization_appid }).FirstOrDefault();
            return item;
        }

        public List<Authorization_Config> GetAuthorization_Configs()
        {
            List<Authorization_Config> items=
                this.GetList<Authorization_Config>(
                    "select * from Authorization_appid_Config where IsDelete=0 and IsStop=0").ToList();
            return items;
        }

        public List<Authorization_info> GetAuthorization_infos()
        {
            var items = this.GetList("select * from Authorization_info ");
            return items.ToList();
        }
    }
}
